#include "zlibhelper.h"
#include <QCryptopp/zlib.h>

ZLibHelper::ZLibHelper(QObject *parent) :
    QObject(parent)
{
}

void ZLibHelper::Compress(QByteArray* buff)
{
    CryptoPP::ZlibCompressor m_ZlibCompressor;
    m_ZlibCompressor.Put(reinterpret_cast<byte*>(buff->data()), buff->size());
    m_ZlibCompressor.MessageEnd();
    size_t outsize = static_cast<size_t>(m_ZlibCompressor.MaxRetrievable());
    char pOut[outsize];
    size_t putSize = m_ZlibCompressor.Get(reinterpret_cast<byte*>(pOut), outsize);
    buff->clear();
    buff->append(pOut,(int)putSize);
}

void ZLibHelper::Decompress( QByteArray* buff)
{
   CryptoPP::ZlibDecompressor m_ZlibDecompressor;
    m_ZlibDecompressor.Put(reinterpret_cast<byte*>(buff->data()), buff->size());
    m_ZlibDecompressor.MessageEnd();
    size_t bytesRetrievable = static_cast<size_t>(m_ZlibDecompressor.MaxRetrievable());
    char pIn[bytesRetrievable];
    size_t getSize = m_ZlibDecompressor.Get(reinterpret_cast<byte*>(pIn),bytesRetrievable);
    buff->clear();
    buff->append(pIn,(int)getSize);
}
